<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>异步组件</title>
  </head>
  <body>
    <div id="app">
      <my-test></my-test>
      <my-com></my-com>
    </div>
  </body> 
  <template id="com">
    <div>组件</div>
  </template>
  <script src="../lib/vue.global.js"></script>
  <script>
    const { defineAsyncComponent } = Vue;
    const Com = {
      template: "#com",
    };

    const MyCom = defineAsyncComponent(() => {
      return new Promise((resolve) => {
        setTimeout(() => {
          resolve(Com);
        }, 3000);
      });
    });

    Vue.createApp({
      components: {
        MyTest: Com,
        MyCom,
      },
    }).mount("#app");
  </script>
</html>
